package com.markus.code.exam.bilibili;

/**
 * Author:markusZhang
 * Date:Create in 2020/9/4 20:33
 * todo:
 */
public class Main4 {
    public static int longestOnes(int[] A, int K) {
        //窗口两端
        int left = 0, right = 0;
        //窗口的最大值
        int max = 0;
        //0的个数
        int zero = 0;

        while (right != A.length) {
            if (A[right++] == 0) {
                zero++;
            }
            //判定条件，0的个数大于K
            while (zero > K) {
                if (A[left++] == 0) {
                    --zero;
                }
            }
            int count = right - left;
            max = max > count ? max : count;
        }
        return max;
    }

    public static void main(String[] args) {
        int []arr = {1,1,1,0,0,0,0,1,1,1,1,0};
        System.out.println(longestOnes(arr,2));
    }
}
